package com.xuhao.examai.question.infrastructure.persistence;

import com.xuhao.examai.question.domain.models.Question;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface QuestionJpaRepository extends JpaRepository<Question, Long> {

	List<Question> findByExamId(Long examId);

	List<Question> findByKnowledgePoint(String knowledgePoint);

	List<Question> findByDifficulty(String difficulty);

	List<Question> findByQuestionType(String questionType);

	@Query("SELECT q FROM Question q WHERE q.content LIKE %:keyword% OR q.knowledgePoint LIKE %:keyword%")
	List<Question> findByKeyword(@Param("keyword") String keyword);

	@Query("SELECT q FROM Question q WHERE q.examId = :examId AND q.difficulty = :difficulty")
	List<Question> findByExamIdAndDifficulty(@Param("examId") Long examId, @Param("difficulty") String difficulty);

	@Query("SELECT q FROM Question q WHERE q.examId = :examId AND q.questionType = :questionType")
	List<Question> findByExamIdAndQuestionType(@Param("examId") Long examId,
			@Param("questionType") String questionType);
}